# Maintainer: Pellegrino Prevete <pellegrinoprevete@gmail.com>

_realname=libhandy
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.0
pkgrel=1
pkgdesc="A library full of GTK+ widgets for mobile phones (mingw-w64)"
url="https://gitlab.gnome.org/GNOME/libhandy"
license=("LGPL2.1+")
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gtk3")
makedepends=("${MINGW_PACKAGE_PREFIX}-glade"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
options=('strip' 'staticlibs' '!debug')
source=("https://download.gnome.org/sources/libhandy/${pkgver:0:3}/libhandy-${pkgver}.tar.xz")
sha256sums=('a9398582f47b7d729205d6eac0c068fef35aaf249fdd57eea3724f8518d26699')

prepare() {
  cd libhandy-${pkgver}
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  ${MINGW_PREFIX}/bin/meson \
    --buildtype=plain \
    -Dexamples=false \
    -Dgtk_doc=false \
    -Dglade_catalog=enabled \
    ../"libhandy-${pkgver}"

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}"/build-${CARCH}
  DESTDIR="${pkgdir}${MINGW_PREFIX}" ${MINGW_PREFIX}/bin/ninja install
  
  local _PRE_WIN="$(cygpath -m ${MINGW_PREFIX})"

  for pcfile in  "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/*.pc; do
    sed -s "s|${_PRE_WIN}|${MINGW_PREFIX}|g" -i "${pcfile}"
  done
}
